package com.ruoyi.project.module.pop.service;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.module.pop.mapper.PopMapper;
import com.ruoyi.project.module.pop.domain.Pop;
import com.ruoyi.project.module.pop.service.IPopService;
import com.ruoyi.common.support.Convert;

/**
 * Pop点 服务层实现
 * 
 * @author ruoyi
 * @date 2018-07-28
 */
@Service
public class PopServiceImpl implements IPopService 
{
	@Autowired
	private PopMapper popMapper;

	/**
     * 查询Pop点信息
     * 
     * @param popId Pop点ID
     * @return Pop点信息
     */
    @Override
	public Pop selectPopById(Integer popId)
	{
	    return popMapper.selectPopById(popId);
	}
	
	/**
     * 查询Pop点列表
     * 
     * @param pop Pop点信息
     * @return Pop点集合
     */
	@Override
	public List<Pop> selectPopList(Pop pop)
	{
	    return popMapper.selectPopList(pop);
	}
	
    /**
     * 新增Pop点
     * 
     * @param pop Pop点信息
     * @return 结果
     */
	@Override
	public int insertPop(Pop pop)
	{
	    return popMapper.insertPop(pop);
	}
	
	/**
     * 修改Pop点
     * 
     * @param pop Pop点信息
     * @return 结果
     */
	@Override
	public int updatePop(Pop pop)
	{
	    return popMapper.updatePop(pop);
	}
	
	
	@Override
	public int updatePopCpe(Pop pop)
	{
	    return popMapper.updatePopCpe(pop);
	}
	
	
	
	
	/**
     * 保存Pop点
     * 
     * @param pop Pop点信息
     * @return 结果
     */
	@Override
	public int savePop(Pop pop)
	{
	    Integer popId = pop.getPopId();
		int rows = 0;
		if (StringUtils.isNotNull(popId))
        {
		    rows = popMapper.updatePop(pop);
		}
		else
        {
		    rows = popMapper.insertPop(pop);
		}
		return rows;
	}
	
	/**
     * 删除Pop点对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deletePopByIds(String ids)
	{
		return popMapper.deletePopByIds(Convert.toStrArray(ids));
	}
	
	
	/**
     * 删除Pop点对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int editPopByIds(String ids,int cpeId)
	{	int key =0;
		String[] idArray = Convert.toStrArray(ids);
		Pop searchPop =new Pop();
		searchPop.setCpeId(cpeId);
		List<Pop> popLst = selectPopList(searchPop);
		for(Pop updatePop :popLst) {
			updatePop.setCpeId(0);
			key = updatePopCpe(updatePop);
		}
		for(String id :idArray) {
			Pop pop =new Pop();
			pop.setPopId(Integer.valueOf(id));
			pop.setCpeId(cpeId);
			key = updatePopCpe(pop);
		}
		return key;
	}
	
}
